﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Users_AskApply : BasePage
{
    string applyId = string.Empty;
    string emId = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString.Count > 0)
        {
            applyId = security.DecryptQueryString(Request.Params["ApplyID"]);
            emId = security.DecryptQueryString(Request.Params["EmID"]);
        }
        DataTable dr_record = Exam.getRecordByApplyId(applyId);
        if (dr_record.Rows.Count > 0)
        {
            DataRow dr = dr_record.Rows[0];
            string askState = dr["AskState"].ToString().Trim();
            if (askState == "1" || askState == "2")
            {
                Response.Redirect(BSUtility.mainUrl + "Users/MyApplyInfo.aspx");
            }
        }
        if (!IsPostBack)
        {
            DataTable dt = Exam.ApplyInfo_GetInfoByID(applyId);
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                NameText.Text = dr["StudName"].ToString();
                SIDText.Text = dr["StudID"].ToString();
                OldRankName.Text = dr["EmRankName"].ToString();
            }
            bindDdlList();
        }
    }
    private void bindDdlList()
    {
        DataTable dt = Exam.getRankNameByEmID(emId);
        BSUtility.BindListControl(ddlRankList, dt, "EmRankName","");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string newRankName = ddlRankList.SelectedItem.Text.ToString().Trim();
        string oldName = OldRankName.Text.Trim();
        string reason = txtReason.Text.Trim();

        if (newRankName.CompareTo(oldName) != 0)
        {
            if (Exam.insertRecord(applyId,newRankName,reason))
            {
                Response.Redirect(BSUtility.mainUrl + "Users/MyApplyInfo.aspx");
            }
        }
        else
        {
            BSUtility.WindowAlert(this, "不能修改为同级别");
        }
    }
}